package com.zis.wechat.service.impl;

import com.zis.base.impl.BaseInterImpl;
import com.zis.core.Constant;
import com.zis.core.ResponseEntity;
import com.zis.wechat.model.TUser;
import com.zis.wechat.service.ITUserInter;
import org.beetl.sql.core.SQLManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Create by wangshen 2018/1/2
 */
@Service
@Transactional("txManager")
public class TUserInterImpl extends BaseInterImpl<TUser> implements ITUserInter {

    @Autowired
    private SQLManager sqlManager;

    @Override
    public String insert(TUser tUser) throws Exception {
        int num = sqlManager.insert(tUser);
        if(num > 0){
            return ResponseEntity.createNormalJsonResponse(Constant.DATA_RESULT_SUCCESS);
        }
        return ResponseEntity.createErrorJsonResponse(Constant.DATA_RESULT_ERROR);
    }

    @Override
    public String update(TUser tUser) throws Exception {
        int num = sqlManager.updateTemplateById(tUser);
        if(num > 0){
            return ResponseEntity.createNormalJsonResponse(Constant.DATA_RESULT_SUCCESS);
        }
        return ResponseEntity.createErrorJsonResponse(Constant.DATA_RESULT_ERROR);
    }

    @Override
    public String delete(String id) throws Exception {
        int num = sqlManager.deleteById(TUser.class, id);
        if(num > 0){
            return ResponseEntity.createNormalJsonResponse(Constant.DATA_RESULT_SUCCESS);
        }
        return ResponseEntity.createErrorJsonResponse(Constant.DATA_RESULT_ERROR);
    }

    @Override
    public TUser selectById(String id) throws Exception {
        return sqlManager.unique(TUser.class, id);
    }

    @Override
    public List<TUser> findByCondition(TUser tUser) throws Exception {
        return sqlManager.template(tUser);
    }
}
